package liangtWorkSpace.Observer.version6;

/**
 * @ClassName Cliend
 * @Description : 功能说明
 * @Author : LiangT
 * @Date : 2020/4/16 18:44
 */

import java.util.ArrayList;
import java.util.List;

/**
 * 加入三个观察者-优化一
 */
public class Cliend {
    private boolean cry = false;
    private List<Observer> observers = new ArrayList<>();
    {
        observers.add(new Dad());
        observers.add(new Mam());
        observers.add(new Dog());
    }

    public boolean isCry(){return cry;}

    public void weakUp(){
        System.out.println("crying ....");
        cry = true;
       WakeUpEvent event =  new WakeUpEvent(12,"bad");
        for (Observer o: observers){
            o.acctionOnWakeUp(event);
        }
    }

    public void weakUp(Observer o){
        System.out.println("crying ....");
        cry = true;
        o.acctionOnWakeUp(new WakeUpEvent(12,"bad"));
    }

    public static void main(String[] args) {
        Cliend cliend = new Cliend();
        cliend.weakUp();
    }
}
class WakeUpEvent {
    long timestamp;
    String loc;

    public WakeUpEvent(long timestamp, String loc) {
        this.timestamp = timestamp;
        this.loc = loc;
    }
}
class Dad implements Observer {
    public void feed(){
        System.out.println("dad feeding.....");
    }

    @Override
    public void acctionOnWakeUp(WakeUpEvent wajeUpEvent) {
        feed();
    }
}

class Mam implements Observer {
    public void feed(){
        System.out.println("dad feeding.....");
    }

    @Override
    public void acctionOnWakeUp(WakeUpEvent wajeUpEvent) {
        feed();
    }
}

class Dog implements Observer {
    public void feed(){
        System.out.println("dad feeding.....");
    }

    @Override
    public void acctionOnWakeUp(WakeUpEvent wajeUpEvent) {
        feed();
    }
}
interface Observer {
    void acctionOnWakeUp(WakeUpEvent wajeUpEvent);
}
